﻿/*
* This software is the confidential and proprietary
* information of NetBay
* Such confidential information should not be disclosed
* NetBay copyright(c) 2011
*/
#region
using System;
using System.Collections.Generic;
using System.Linq;
using NetBay.Core.BusinessEntities;
using System.Data;
using NetBay.Core.BusinessEntities.DashBoard;

#endregion

namespace Rio.Manager.Business.Repository.Translator
{
    public class DashBoardTranslator
    {
        /// <summary>
        /// Get numerization informations by operator
        /// </summary>
        /// <returns></returns>
        public static List<NumerizationOperator> GetNumerizationReportByOperator(IDataReader P_oDbDataReader)
        {
            var Operators = new List<NumerizationOperator>();
            try
            {
                using (P_oDbDataReader)
                {
                    while (P_oDbDataReader.Read())
                    {
                        NumerizationOperator numerizationOperator = Operators.Where(item => item.FullName == P_oDbDataReader["USER_NAME"].ToString()).FirstOrDefault();

                        if (numerizationOperator == null)
                        {
                            numerizationOperator = new NumerizationOperator();
                            numerizationOperator.UserId = long.Parse(P_oDbDataReader["USER_ID"].ToString());
                            numerizationOperator.FullName = P_oDbDataReader["USER_NAME"].ToString();
                            numerizationOperator.NbFileScan = int.Parse(P_oDbDataReader["NB_TOTAL_DOCUMENT"].ToString());
                            numerizationOperator.NbFolderProcessed = int.Parse(P_oDbDataReader["NB_TREATED_FOLDER"].ToString());
                            numerizationOperator.NbFolderToReview = int.Parse(P_oDbDataReader["NB_FOLDER_INCOMPLETE"].ToString());

                            Operators.Add(numerizationOperator);
                        }
                        else
                        {
                            numerizationOperator.NbFileScan += int.Parse(P_oDbDataReader["NB_TOTAL_DOCUMENT"].ToString());
                            numerizationOperator.NbFolderProcessed += int.Parse(P_oDbDataReader["NB_TREATED_FOLDER"].ToString());
                            numerizationOperator.NbFolderToReview += int.Parse(P_oDbDataReader["NB_FOLDER_INCOMPLETE"].ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                NetBay.Core.Log.LogManager.Instance().LogError("EXCEPTION -> " + Environment.NewLine + ex);
            }
            return Operators;
        }

        /// <summary>
        /// Get numerization informations
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public static NumerizationResum GetNumerizationReport(IDataReader P_oDbDataReader)
        {
            var resum = new NumerizationResum();
            try
            {
                using (P_oDbDataReader)
                {
                    while (P_oDbDataReader.Read())
                    {
                        resum.FilesScanned = int.Parse(P_oDbDataReader["NB_TOT_DOC"].ToString());
                        resum.FoldersProcessed = int.Parse(P_oDbDataReader["NB_TOT_FLD_TRT"].ToString());
                        resum.FoldersToReview = int.Parse(P_oDbDataReader["NB_TOT_FLD_INC"].ToString());
                        resum.TotalFoldersCount = int.Parse(P_oDbDataReader["NB_TOT_FLD"].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                NetBay.Core.Log.LogManager.Instance().LogError("EXCEPTION -> " + Environment.NewLine + ex);
            }
            return resum;
        }
    }
}